
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
</head>
<body>
    <button class="reg-btn">注册用户</button>


    <script>
        // 通过 XHR 提交用户名和密码，完成注册功能
        document.querySelector(".reg-btn").addEventListener("click",function () {
            const  xhr = new XMLHttpRequest()
    
           
            xhr.open("POST","http://hmajax.itheima.net/api/register")
    
            xhr.addEventListener("loadend",function () {
                console.log(xhr.response);
                const data = JSON.parse(xhr.response)
                
            
                
            })
            // 设置请求头 内容类型
            xhr.setRequestHeader('Content-Type', 'application/json');
    
            // 提交的数据
            const  userObj = {
                username:"fbs00001",
                password:"111111"
            }
            
            const userStr = JSON.stringify(userObj)
            xhr.send(userStr)
            
        })


    </script>
</body>
</html>